<template>
  <div>
    <input type="text" placeholder="输入要添加的todo项,并且按回车添加" id="searchBar" v-model="itemTitle" @keyup.enter="addItem">
  </div>
</template>

<script>
// import TodoBody from "./TodoBody.vue"
import eventBus from '../js/eventBus'
import StringUtil from '../js/utils/stringUtil'
export default {
 name: 'TodoHeader',
 data() {
  return {
    itemTitle:""
  }
 },
 methods:{ 
  addItem(){
    if(StringUtil.emptyString(this.itemTitle)){
       alert("Todo Item不能为空") 
       return
    }
   eventBus.$emit(eventBus.addItemEvent,{title:this.itemTitle,done:false})
   this.itemTitle=""
  }
 }
}
</script>

<style scoped>
 #searchBar {
  height:30px;
  width: 500px;
 }
</style>